﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Xierun.Models.Core;

namespace Xierun
{
    public interface IBaseService<T> where T : Entity
    {
        
        bool Add(T entity, bool isSaveChange = true);
        Task<bool> AddAsync(T entity, bool isSaveChange = true);
        bool BatchAdd(T[] entities, bool isSaveChange = true);
        Task<bool> BatchAddAsync(T[] entities, bool isSaveChange = true);
        bool BatchInsert(T[] entities, bool isSaveChange = true);
        Task<bool> BatchInsertAsync(T[] entities, bool isSaveChange = true);
        //void Delete(Expression<Func<T, bool>> exp);
        bool Delete(List<T> entitis, bool isSaveChange = true);
        bool Delete(T entity, bool isSaveChange = true);
        Task<bool> DeleteAsync(List<T> entitis, bool isSaveChange = true);
        Task<bool> DeleteAsync(T entity, bool isSaveChange = true);
        bool DeleteById(string id, bool isSaveChange = true);
        Task<bool> DeleteByIdAsync(string id, bool isSaveChange = true);
        int ExecuteSql(string sql);
        int GetCount(Expression<Func<T, bool>> exp = null);
        Task<int> GetCountAsync(Expression<Func<T, bool>> exp = null);
        List<T> GetList(Expression<Func<T, bool>> exp = null);
        List<T> GetList(int pageIndex, int pageSize, string orderBy = "", Expression<Func<T, bool>> exp = null);
        Task<List<T>> GetListAsync(Expression<Func<T, bool>> exp = null);

        Task<List<T>> GetListAsync(int pageIndex, int pageSize, string orderBy = "",
            Expression<Func<T, bool>> exp = null);

        T GetSingle(Expression<Func<T, bool>> exp);
        Task<T> GetSingleAsycn(Expression<Func<T, bool>> exp);
        T GetSingleById(string id);
        Task<T> GetSingleByIdAsync(string id);
        bool Insert(T entity, bool isSaveChange = true);
        Task<bool> InsertAsync(T entity, bool isSaveChange = true);
        bool IsExist(Expression<Func<T, bool>> exp);
        Task<bool> IsExistAsync(Expression<Func<T, bool>> exp);
        int SaveChanges();
        Task<int> SaveChangesAsync();
        //void UpdatePart(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity);
        bool Update(List<T> entitis, bool isSaveChange = true);
        bool Update(T entity, bool isSaveChange = true, List<string> updatePropertyList = null);
        Task<bool> UpdateAsync(List<T> entitis, bool isSaveChange = true);
        Task<bool> UpdateAsync(T entity, bool isSaveChange = true, List<string> updatePropertyList = null);
    }
}